<template>
	<view class="content">
		<u-navbar :is-back="false" :title="title" title-color="white" :background="background"></u-navbar>
		<view class="search">
			<u-search maxlength="10" placeholder="搜索" v-model="resQuery.name" @search="searchMe" @custom="searchMe">
			</u-search>
		</view>
		<view class="wrap">
			<u-swiper :list="list" height="350"></u-swiper>
		</view>
		<view class="item_wrap" v-for="(info, index) in infoList" :key="index">
			<navigator :url="'../good_detail/good_detail?id=' + info.id">
				<view class="card" @click="pageView">
					<view class="top">
						<text>{{info.name}}</text>
					</view>

					<view class="middle">
						<view class="left">
							<image :src="baseimg_url +info.picture" mode="aspectFit"></image>
						</view>
						<view class="right">
							<view class="content">
								<text>
									{{info.description}}
								</text>
							</view>
							<view class="tags">
								<view class="item">
									{{(info.resType == 0)?"失物招领":((info.resType == 1)?"寻物启事":" ")}}
								</view>

							</view>
						</view>
					</view>

					<view class="bottom">
						<view class="left">
							{{info.gmtModify}}
						</view>
						<view class="right">
							<view class="comments">

							</view>
							<view class="comments">

							</view>
							<view class="comments">
								<!-- <u-icon name="eye" color="#99CCFF"></u-icon>
								<text>101</text> -->
							</view>
						</view>
					</view>
				</view>
			</navigator>
		</view>
	</view>
</template>

<script>
	var me, page = 1,limit = 5;

	import {
		mapGetters
	} from 'vuex'
	export default {
		data() {
			return {
				baseimg_url: this.baseimgUrl,
				title: "首页",
				background: {
					backgroundImage: 'linear-gradient(120deg, #f6d365 0%, #fda085 100%)'
				},
				keyword: ' ',
				list: [{
					image: 'https://cdn.uviewui.com/uview/swiper/1.jpg',
					title: '昨夜星辰昨夜风，画楼西畔桂堂东'
				}],
				infoList: [],
				pageview:0,
				png: "../../static/back_png.png",
				resQuery: {
					name: ''
				}
			}
		},
		onLoad() {
			//首页物品显示
			this.getNewsList();
			this.searchMe();
		},
		onPullDownRefresh: function() {
			page = 1;
			me.infoList = [],
			this.getNewsList();
			
		},
		// 加载更多
		onReachBottom: function() {
			this.getNewsList();
		},
		methods: {
			getNewsList: function() {
				me = this;
				uni.request({
					url: me.baseUrl + '/mini_program/res/getPageResList/' + page + '/' + limit,
					method: 'POST',
					data: {
						"name": me.resQuery.name
					},
					success: res => {
						
						me.goods_detail = res;
						var totalinfo = res.data.data.total;
						var last_num = totalinfo - (page - 1) * limit
						if (!res.data.data.hasNext) {
							if (totalinfo - (page - 1) * limit <= 0) {
								uni.showToast({
									title: "已经没有了~",
									icon: "none"
								});
							}
						}
						if (last_num > 0 && res.data.code == 20000) {
							uni.showLoading({
								'title': "加载中..."
							});
							//整理新闻信息
							var datainfo = res.data.data.rows;
							me.infoList = me.infoList.concat(datainfo);
							/* console.log(totalinfo);
							console.log(me.infoList); */
							uni.hideLoading();
							page++;
						}
					},
					complete: function() {
						uni.stopPullDownRefresh();
					}
				});
			},
			searchMe() {
				me = this;
				page = 1;
				me.infoList = [],
				this.getNewsList();
				/* uni.showToast({
					title: "搜索完成",
					icon: "none"
				}); */
			},
			pageView(){
				var me =this;
				uni.request({
					url:me.baseUrl + "/mini_program/page-view/add",
					method: 'POST',
					success: res => {
						console.log(res.data.data)
						
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		.search {
			margin: 10rpx 20rpx;
		}

		.wrap {
			height: 300rpx;
			margin-bottom: 80rpx;
		}

		.card {
			width: 700rpx;
			height: 250rpx;
			display: flex;
			flex-direction: column;
			margin: 20rpx auto;
			border-radius: 20rpx;
			background-color: #F1F1F1;
			// background-color: rgba($color: #000000, $alpha: 0.2);

			.top {
				text {
					font-size: 35rpx;
					font-weight: bold;
					display: -webkit-box;
					-webkit-line-clamp: 1;
					-webkit-box-orient: vertical;
					overflow: hidden;
					margin: 5rpx 10rpx;
				}
			}

			.middle {
				display: flex;
				height: 200rpx;

				.left {

					//background-color: rgba($color: #000000, $alpha: 0.3);
					image {
						width: 250rpx;
						height: 150rpx;
						margin: 0 20rpx 10rpx 10rpx;
						border-radius: 10rpx;

					}
				}

				.right {
					flex: 1;

					.content {
						text {
							display: -webkit-box;
							-webkit-line-clamp: 3;
							-webkit-box-orient: vertical;
							overflow: hidden;
						}
					}

					.tags {
						display: flex;
						width: 400rpx;
						white-space: nowrap;
						overflow: hidden;

						.item {
							margin-right: 20rpx;
							background-color: rgba($color: #000000, $alpha: 0.08);
							padding: 5rpx 10rpx;
							border-radius: 5rpx;
							font-size: 25rpx;

						}
					}
				}
			}

			.bottom {
				// flex: 1;
				display: flex;
				// background-color: rgba($color: #000000, $alpha: 0.5);
				height: 70rpx;
				align-items: center;
				justify-content: space-between;

				.left {
					font-size: 30rpx;
					margin-left: 10rpx;
				}

				.right {
					flex: 1;
					display: flex;
					justify-content: space-around;
					margin: 0 40rpx;

					.comments {
						text {
							margin-left: 8rpx;
						}
					}

					.zan {
						text {
							margin-left: 8rpx;
						}
					}

					.view {
						text {
							margin-left: 8rpx;
						}
					}
				}
			}
		}
	}
</style>
